package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.WorkYear;
import com.sgb.kjwl.view.ui.adapter.pick.WorkYearAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

/**
 * 工龄popwindow
 */
public class AgePopWindow extends BasePopWindow {

    private RecyclerView recyclerView;
    private TextView okView;
    private TextView resetView;
    private LinearLayout bottomLayout;
    private WorkYearAdapter pickAdapterCity;
    private List<WorkYear> years;
    private int no ;
    private String name = "";
    private int position = -1;

    public AgePopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_area_two;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.rlv_list);
        bottomLayout = holder.getPop().findViewById(R.id.bottom_layout);

        pickAdapterCity = new WorkYearAdapter(mContext, null, R.layout.item_pick_year);
        pickAdapterCity.setItemSelect(true);
        pickAdapterCity.setDefItem(-1);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(pickAdapterCity);
        pickAdapterCity.setOnItemClick(new AdapterOnItemClick<WorkYear>() {
            @Override
            public void onItemClick(WorkYear pickSelectEntity, int position) {
                no = pickSelectEntity.getType();
                name = pickSelectEntity.getDesc();
                if (onResultClick != null) {
                    onResultClick.result(no, name, position);
                    Log.d("工龄编号", ""+no);
                }
                dissMiss();
            }
        });
    }

    public void setData(List<WorkYear> cityDatas) {
        this.years = cityDatas;
        pickAdapterCity.setDatas(cityDatas);

    }

    public void setData(List<WorkYear> cityDatas, int position) {
        this.years = cityDatas;
        pickAdapterCity.setDatas(cityDatas);
        pickAdapterCity.setDefItem(position);
    }

    public void setVisibleList(boolean visible) {
        recyclerView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
    }

    public void setDefData(int position) {
        pickAdapterCity.setDefItem(position);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if(onDisMiss!=null)
        onDisMiss.disMiss();
    }
}
